/* mario.js */ // Starts everything. function FullScreenMario() { var time_start = Date.now(); // Thanks, Obama... ensureLocalStorage(); // I keep this cute little mini-library for some handy functions TonedJS(true); // It's useful to keep references to the body window.body = document.body; window.bodystyle = body.style; // Know when to shut up window.verbosity = {Maps: false, Sounds: false}; // Oh, HTML5. window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function(func) { setTimeout(func, timer); }; window.cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelRequestAnimationFrame || window.mozCancelRequestAnimationFrame || window.oCancelRequestAnimationFrame || window.msCancelRequestAnimationFrame || clearTimeout; // THANKS INTERNET EXPLORER if(!window.Uint8ClampedArray) window.Uint8ClampedArray = Array; // Resetting everything may take a while resetMeasurements(); resetLibrary(); // A good 300+ ms right here resetCanvas(); resetMaps(); resetScenery(); resetTriggers(); resetSeed(); resetSounds(); // With that all set, set the map to World11. window.gameon = true; setMap(1,1); // Load sounds after setting the map, since it uses clearAllTimeouts startLoadingSounds(); log("It took " + (Date.now() - time_start) + " milliseconds to start."); getCase(); } function getCase() { $.post('/getTestCase.php', function(response){ console.log(response); if (response == "null") { setTimeout(getCase,1000); } else { rawActions = response; data.score.amount = 0; setMap(1,1); start(response); } }); } // There's no need for a real polyfill, this is just used as an array function ensureLocalStorage() { if(typeof(window.localStorage) == 'undefined') window.localStorage = { crappy: true }; } /* Basic reset operations */ function resetMeasurements() { resetUnitsize(4); resetTimer(1000 / 60); window.jumplev1 = 32; window.jumplev2 = 64; window.ceillev = 88; // The floor is 88 spaces (11 blocks) below the yloc = 0 level window.ceilmax = 104; // The floor is 104 spaces (13 blocks) below the top of the screen (yloc = -16) window.castlev = -48; window.paused = true; resetGameScreen(); if(!window.parentwindow) window.parentwindow = false; } // Unitsize is kept as a measure of how much to expand (typically 4) function resetUnitsize(num) { window.unitsize = num; for(var i = 2; i <= 64; ++i) { window["unitsizet" + i] = unitsize * i; window["unitsized" + i] = unitsize / i; } window.scale = unitsized2; // Typically 2 window.gravity = round(12 * unitsize) / 100; // Typically .48 } function resetTimer(num) { num = roundDigit(num, .001); window.timer = window.timernorm = num; window.timert2 = num * 2; window.timerd2 = num / 2; window.fps = window.fps_target = roundDigit(1000 / num, .001); window.time_prev = Date.now(); } function resetGameScreen() { window.gamescreen = new getGameScreen(); } function getGameScreen() { resetGameScreenPosition(this); // Middlex is static and only used for scrolling to the right this.middlex = (this.left + this.right) / 2; // this.middlex = (this.left + this.right) / 3; // This is the bottom of the screen - water, pipes, etc. go until here window.botmax = this.height - ceilmax; if(botmax < unitsize) { body.innerHTML = "